package com.xuexiang.xuidemo.slice.button;

import com.xuexiang.xui_lib.popup.GoodComponent;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.slice.BaseAbilitySlice;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.utils.Color;
import ohos.global.resource.NotExistException;
import ohos.global.resource.Resource;

import java.io.IOException;

/**
 * 点赞
 */
public class GoodButtonSlice extends BaseAbilitySlice {

    //private PixelMapElement mGoodCheckBg;

    @Override
    protected int getUIContentLayoutId() {
        return ResourceTable.Layout_good_button_slice;
    }

    @Override
    protected int getTitleBarId() {
        return ResourceTable.Id_title_bar;
    }

    @Override
    protected void initComponents() {
        super.initComponents();
        initCheckedBg();
        Image image = (Image) findComponentById(ResourceTable.Id_btn_test);
        Image image1 = (Image) findComponentById(ResourceTable.Id_btn_test1);
        Image image2 = (Image) findComponentById(ResourceTable.Id_btn_test2);
        Image image3 = (Image) findComponentById(ResourceTable.Id_btn_test3);
        image.setClickedListener(component -> {
            new GoodComponent(component.getContext(), component)
                    .setTextColor(Color.getIntColor("#f66467"))
                    .setTextX("+1").show();
            image.setPixelMap(ResourceTable.Media_ic_good_checked);
        });
        image1.setClickedListener(component -> {
            new GoodComponent(component.getContext(), component)
                    .setBackgroundRes(ResourceTable.Media_ic_good_checked)
                    .show();
            image1.setPixelMap(ResourceTable.Media_ic_good_checked);
        });
        image2.setClickedListener(component -> {
            new GoodComponent(component.getContext(), component)
                    .setTextColor(Color.getIntColor("#f66467"))
                    .setTextX("收藏成功")
                    .show();
            image2.setPixelMap(ResourceTable.Media_ic_collection_checked);
        });
        image3.setClickedListener(component -> {
            new GoodComponent(component.getContext(), component)
                    .setTextColor(Color.getIntColor("#ff941A"))
                    .setTextX("收藏成功")
                    .show();
            image3.setPixelMap(ResourceTable.Media_ic_bookmark_checked);
        });
        findComponentById(ResourceTable.Id_reset_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                image.setPixelMap(ResourceTable.Media_ic_good);
                image1.setPixelMap(ResourceTable.Media_ic_good);
                image2.setPixelMap(ResourceTable.Media_ic_collection);
                image3.setPixelMap(ResourceTable.Media_ic_bookmark);
            }
        });
    }

    private void initCheckedBg() {
       /* try {
            // 选中图
            Resource goodRes = getResourceManager().getResource(ResourceTable.Media_ic_good_checked);
            //mGoodCheckBg = new PixelMapElement(goodRes);
            } catch (IOException e) {
            e.printStackTrace();
        } catch (NotExistException e) {
            e.printStackTrace();
        }*/
    }

}
